package main

import (
	"github.com/gin-gonic/gin"
	"net/http"
)

/**
验证请求参数 - 结构体验证
具体验证规则参考链接： https://godoc.org/gopkg.in/go-playground/validator.v8
*/
func main() {
	r := gin.Default()

	r.GET("/testing", func(c *gin.Context) {
		var person Person
		if err := c.ShouldBind(&person); err != nil {
			c.String(http.StatusInternalServerError, "%v", err)
			c.Abort()
		}

		c.String(http.StatusOK, "%v", person)
	})

	r.Run()
}

/**
binding
任意一个可以满足用“|”
两个都必须满足用","

form、binding后面不能有空格
*/
type Person struct {
	Age     int    `form:"age" binding:"required,gt=10"`
	Name    string `form:"name" binding:"required"`
	Address string `form:"address" binding:"required"`
}
